package cz.vutbr.fit.xzemko01.tfmcbs.validation.utils;

import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;

public class DiagnosticBuilder {
	private int severity = Diagnostic.ERROR;
	private String diagnosticSource = "org.eclipse.emf.ecore";
	private int code;
	private String message;
	private Object[] data;	
	
	public DiagnosticBuilder(Object problemSource) {
		data = new Object[] { problemSource };
	}
	
	public Diagnostic build() {
		if(severity != Diagnostic.ERROR && severity != Diagnostic.INFO 
				&& severity != Diagnostic.WARNING && severity != Diagnostic.OK) 
		{
			throw new IllegalStateException("Diagnostic severirity has illegal value.");
		}
		
		if(diagnosticSource == null) {
			throw new IllegalStateException("Diagnostic source is null.");
		}
		if(message == null || message.trim().isEmpty()) {
			throw new IllegalStateException("Diagnostic message must be set.");
		}
		
		return new BasicDiagnostic(
                severity,
                diagnosticSource,
                code,
                message,
                data);
	}
	
	public DiagnosticBuilder setSeverity(int severity) {
		this.severity = severity;
		return this;
	}
	
	public DiagnosticBuilder setDiagnosticSource(String diagnosticSource) {
		this.diagnosticSource = diagnosticSource;
		return this;
	}
	
	public DiagnosticBuilder setCode(int code) {
		this.code = code;
		return this;
	}
	
	public DiagnosticBuilder setMessage(String message) {
		this.message = message;
		return this;
	}
	
	public DiagnosticBuilder setData(Object[] data) {
		this.data = data;
		return this;
	}
}
